#ifndef _FONTATLASMAKER_H_INCLUDED_
#define _FONTATLASMAKER_H_INCLUDED_

#include <GlobalData.h>
#include <vector>
#include <string>

struct FT_LibraryRec_;
struct FT_FaceRec_;
class FTBitmapChar;
class FTBitmapFont;
class GLCallBatcher;

class FontAtlas
{
private:
    std::vector<FTBitmapChar*>          listBitmapChar;
	std::vector<FTBitmapFont*>          listBitmapFont;
	std::vector<FT_FaceRec_*>           listFace;
	FT_LibraryRec_                      *library;
	FTBitmapChar                        *showAtlas;
	bool                                useKerning;
	unsigned int                        textureID;
    uint                                maxTextureWidth;
    uint                                maxTextureHeight;
    GLCallBatcher                       *batcher;
    
private:
	bool            binPack(int width, int height);
	void            releaseTexture();
	void            releaseLibrary();
    
public:
	FontAtlas(GLCallBatcher *glCallBatcher, uint maxTextureWidth = 2048, uint maxTextureHeight = 2048);
	~FontAtlas();
    
	bool            addFont(/*const char *fontName*/const void* fontData, off_t fontLen, int size, const wchar_t* szLetters);
	void            createAtlas();
  	void            renderAtlas(int x, int y);
    bool            getNextTextureSize(int &texWidth, int &texHeight, int ixSize);
    
	void            setUseKerning(bool useKerning)  { this->useKerning = useKerning; }
	FTBitmapFont*   getFont(int index)              { return listBitmapFont[index]; }
	unsigned int    getTextureID() const            { return textureID; }
	void            setTextureID(unsigned int newTexId) { textureID = newTexId; }
	bool            getUseKerning() const           { return useKerning; }
    GLCallBatcher   *getBatcher() const             { return batcher; }
};





#endif // _FONTATLASMAKER_H_INCLUDED_
